<template>
  <div class="hello">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="邮箱">
        <el-input v-model="form.email"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getToken } from '@/utils/auth' // getToken from cookie
export default {
  name: 'login',
  data () {
    return {
      form: {
        email: 'test@a.com',
        password: '123123'
      }
    }
  },
  created () {
    if (getToken()) {
      this.$router.push({ path: '/index' })
    }
  },
  methods: {
    onSubmit () {
      const params = {
        email: this.form.email,
        password: this.form.password
      }
      this.$store.dispatch('Login', params).then(() => {
        this.$store.dispatch('GetInfo').then(res => {
          this.$router.push('/index')
        })
      })
    }
  }
}
</script>

<style scoped>
.hello {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
